﻿@model PageListViewModel
@{
    ViewBag.Title = @Strings.Pages;
}

@using (Html.BeginForm())
{ 
    <fieldset class="shaded">
        <legend>@Strings.Pages</legend>
        @Html.ActionLink(Strings.Page_Create, "Create", "Page")
        @(Html.Grid(Model.Data).Columns(column =>
    {
        column.For(x => x.Title);
        column.For(x => x.Author.FullName).Sortable(true);
        column.For(x => x.PublishDate).Sortable(true);
        column.For(x => Html.ActionLink(Strings.Edit, "Edit", new { id = x.PageId }) +
                    String.Format(" | <a href='javascript:void(0)' id='{0}' class='deleteLink' title='{1}'>{2}</a>", x.PageId, x.Title, Strings.Delete)).DoNotEncode();

    }).Sort(Model.GridSortOptions))
        @Html.Pager(Model.PagingInfo)
    </fieldset>
}

@section head {
    <script type="text/javascript">
        $(document).ready(function () {
            $(".deleteLink").click(function () {
                var message = '@Html.Raw(Strings.Page_ConfirmDeleteFormatString)'.replace('{0}', $(this).attr("title"));
                if (confirm(message) == false)
                    return false;

                $.post("/Page/Delete/", { 'id': $(this).attr("id") }, function (data) {
                    if (data.Success == true) {
                        document.location.reload();
                    }
                    else {
                        alert(data.Message);
                    }
                });
            });
        });
    </script>
}
